package Simulator;

import java.util.List;

import Shared.Map;
import Shared.MapPosition;

/**
 * The GPS module, see Architecture report for specifications.
 */

public class GPS {
	private final RealAmbulance amb;
	private final Map map;

	/**
	 * Creates a GPS for Ambulance amb
	 * 
	 * @param amb
	 *            != null
	 */
	public GPS(RealAmbulance amb) {
		assert amb != null;

		this.amb = amb;
		this.map = Map.getInstance();
	}

	/**
	 * Locates the ambulance
	 * 
	 * @return the physical position of the ambulance
	 */
	public MapPosition getAmbulancePosition() {
		return this.map.getNearestPos(this.amb.getPosition());

	}

	/**
	 * Computes the shortest path between the ambulances position and dest
	 * 
	 * @param dest
	 *            the destination
	 * @return a list of positions corresponding to the shortest path
	 */
	public List<MapPosition> computePath(MapPosition dest) {
		if (this.map.getNearestPos(dest).equals(this.map.getNearestPos(this.getAmbulancePosition())))
			return null;
		List<MapPosition> list = map.computePath(this.map.getNearestPos(this.getAmbulancePosition()),
				this.map.getNearestPos(dest));
		return list;
	}

}
